package org.extreme.script.core.parser;

import org.extreme.script.CalculateContext;

public class Ambiguity extends Tiny {
	private String statement;

	Ambiguity(String statement) {
		this.statement = statement;
	}
	
	public String getStatement() {
		return this.statement;
	}
	
	public Object eval(CalculateContext calculator) throws UtilEvalError {
        if (statement == null) {
            throw new UtilEvalError("statement in literal is null");
        }

        Object obj = calculator.resolveVariable(statement);

        if (obj == null) {
            throw new UtilEvalError("null field resolved: " + statement);
        }

        return obj;
    }
	
	public String toString() {
		return statement;
	}

	public String getExpression(int rowIndex, int rowChanged, int columnIndex, int colChanged, boolean isParameter) {
		return null;
		// TODO:
//		ColumnRow columnrow = ColumnRow.valueOf(statement.substring(1));
//		if (!isParameter && statement.startsWith("$") && ColumnRow.validate(columnrow)){
//			int newColumnIndex = columnrow.getColumn();
//	        if (columnIndex != -1 && columnrow.getColumn() >= columnIndex) {
//	        	newColumnIndex += colChanged;
//	        }
//
//	        int newRowIndex = columnrow.getRow();
//	        if (rowIndex != -1 && columnrow.getRow() >= rowIndex) {
//	            newRowIndex += rowChanged;
//	        }
//	        
//	        columnrow = ColumnRow.valueOf(newColumnIndex, newRowIndex);
//	        return "$" + columnrow.toString();
//		}
//		return this.toString();
	}
	
	public String[] parserParameter() {
		return null;//StringUtils.isBlank(statement) ? null : new String[]{statement};
	}
}
